/**
 * yiqihao(一起好商务股份有限公司) copyright 
 */
package com.p2p.front.jms.consumer.funds;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.p2p.base.model.Money;
import com.p2p.base.model.P2PRecharge;
import com.p2p.front.enums.UserCreditsType;
import com.p2p.front.service.UserCreditsService;

/**
 *
 * @author leiruiqi@yiqihao.com
 *
 * 2015年1月29日 上午8:59:59
 */
public class RechargeListener implements MessageListener{

	private final Logger logger = LoggerFactory.getLogger(RechargeListener.class);

	@Resource
	private UserCreditsService userCreditsService;
	
	@Override
	public void onMessage(Message message) {
		P2PRecharge p2pRecharge =  null;
		ObjectMessage objMsg = (ObjectMessage) message;
		try {
			Object o = objMsg.getObject();
			p2pRecharge = (P2PRecharge)o;
		}catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(p2pRecharge!=null){
			Money amount = p2pRecharge.getMoney();
			userCreditsService.addValue(p2pRecharge.getUid(), UserCreditsType.UserCreditsNeedCharge, amount.getCent());
			logger.info("Recharge listener for UserCreditsNeedCharge update,uid="+p2pRecharge.getUid()+",amount = "+amount.toString() );
		}
		
		
	}
}
